<?php

namespace System\Core;

if (!defined('BASEPATH')) die('Access Denied.');

/**
 * µMVC Framework (c) 2011.
 * 
 * PHP5 MVC Framework software for PHP 5.2.17 or later
 * 
 * @package         µMVC
 * @filename        system/core/model.class.php
 * @copyright       Lanz (c) 2011.
 * 
 */

class ModelException extends CommonException {}

/**
 * Model class
 * The base model class.
 * 
 * @package         µMVC
 * @subpackage      Core
 * @category        System
 */

class Model {

    /** 
     * We break conventions here and do not add the _ for 
     * private variables just to make it easier to type in the application 
     * later on.
     */

    /**
     * The registry object holds instances to the database, models and libraries.
     * 
     * @var object 
     */
    protected $registry;
        
    function __construct()
    {
        $this->registry = Registry::instance();
        
        Log::instance()->write(Log::DEBUG, 'Model Class Intitialized');
    }

    /**
     * Magic method just so we can write $this->db instead of having to type
     * $this->registry->db. Yeah I'm a lazy bastard :) 
     */
    public function __get($key)
    {
        if (isset($this->registry->{$key}))
        {
            return $this->registry->{$key};
        }
        else
        {
            throw new ModelException("$key is not defined in the registry object.");
        }
    }
    
}
?>
